package com.jxb.test20241216;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/12/23 23:12
 **/
public class Sort4 {

    public static void main(String[] args) {
        int i = 2/2;
        System.out.println(i);
    }

    public static int[] sortArray(int[] nums) {
        //获取增量序列
        Queue<Integer> is = new LinkedList<>();
        int el = nums.length;
        while (el != 1) {
            el = el/2;
            is.offer(el);
        }
        //通过增量序列进行排序
        while (!is.isEmpty()) {
            Integer curIs = is.poll();
            for (int i = 0;i<nums.length-curIs;i=i+curIs) {
                int preIndex = i;
                int currentValue = nums[preIndex+curIs];
                while (preIndex >= 0 && currentValue < nums[preIndex]) {
                    nums[preIndex + curIs] = nums[preIndex];
                    preIndex = preIndex - curIs;
                }
                nums[preIndex + curIs] = currentValue;
            }
        }
        return nums;
    }

}
